package _18_剑指OfferII;

public class _090_剑指OfferII环形房屋偷盗 {

    public int rob(int[] nums) {
        if (nums.length == 1) return nums[0];

        return Math.max(rob(nums, 0, nums.length - 1), rob(nums, 1, nums.length));
    }

    public int rob(int[] nums, int begin, int end) {
        int first = 0;
        int second = 0;
        for (int i = begin; i < end; i++) {
            int temp = second;
            second = Math.max(nums[i] + first, second);
            first = temp;
        }
        return second;
    }
}
